<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>高校宿舍管理系统-假期留校管理</title>
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="../../layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layui/css/public.css" media="all">
    <link rel="stylesheet" href="../../layui/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">宿舍区</label>
                            <div class="layui-input-inline">
                                <input type="text" name="brarea" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">楼栋</label>
                            <div class="layui-input-inline">
                                <input type="text" name="brbid" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon"></i>查 询
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <!-- 表格头部工具栏 -->
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button id="exportExcel" class="layui-btn layui-btn-sm data-add-btn" lay-event="export">
                    <i class="layui-icon layui-icon-export"></i>导出
                </button>
            </div>
        </script>

        <div class="layui-row layui-col-space15">
            <div class="layui-col-xs12 layui-col-md9" style="text-align: center;margin-top: 50px;">
                <div id="echarts-pies" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
            </div>
        </div>
    </div>
</div>
<script src="../layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../layui/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layer', 'echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            table = layui.table,
            echarts = layui.echarts;

        var tableIns = table.render({
            elem: '#currentTableId',
            url: '/dm/stayin/list',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {field: 'brarea', width: 110, title: '宿舍区'},
                    {field: 'brbid', width: 80, title: '楼栋'},
                    {field: 'brrid', width: 80, title: '寝室'},
                    {field: 'stuid', width: 130, title: '学号'},
                    {field: 'stuname', width: 100, title: '姓名'},
                    {field: 'reason', minWidth: 200, title: '留校原因'},
                    {field: 'time', width: 120, title: '留校截止时间'},
                    {field: 'stucollege', width: 110, title: '学院'},
                    {field: 'studept', width: 110, title: '专业'},
                    {field: 'stuclass', width: 100, title: '班级'},
                    {field: 'stutel', width: 130, title: '联系方式'},
                    {field: 'stututortel', width: 130, title: '家长联系方式'}
                ]
            ],
            limits: [5, 10, 20],
            limit: 5,
            page: true,
            skin: 'line',
            even: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            console.log(data.field);

            // 执行搜索重载
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        $(function () {
            getPieData();
        });

        /**
         * 获取饼状图的数据
         */
        function getPieData() {
            $.ajax({
                type: "get",
                url: "/dm/stayin/echartsData",
                async: true,
                dataType: "json",
                success: function (result) {
                    console.log(result);
                    var echartsPies = echarts.init(document.getElementById('echarts-pies'), 'walden');
                    var optionPies = {
                        title: {
                            text: '留校学生住宿分布图',
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'right',
                            data: result.data
                        },
                        series: [
                            {
                                name: '宿舍区',
                                type: 'pie',
                                radius: '60%',
                                center: ['50%', '50%'],
                                roseType: 'radius',
                                data: result.series,
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    echartsPies.setOption(optionPies, true);
                },
                error: function () {
                    layer.msg("网络错误！", {icon: 2});
                }
            });
        }

        function hoverOpenImg() {
            var imgShow = null; // tips提示
            $('td img').hover(function () {
                var img = "<img src='" + $(this).attr('src') + "' style='width:100%;height: 100%' />";
                imgShow = layer.tips(img, this, {
                    tips: [2, 'rgba(41,41,41,.5)'],
                    area: ["350px", "350px"]
                });
            }, function () {
                layer.close(imgShow);
            });
        }

        //表格头部工具栏触发事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === "export") {
                window.location.href = "/dm/stayin/export.action";
            };
        });

    });
</script>
</body>
</html>